<?php
namespace app\mall\controller\admin;


use app\mall\enum\YesNoEnum;
use suframe\thinkAdmin\traits\CURDController;
use suframe\thinkAdmin\ui\UITable;
use app\mall\model\MallLogisticsCompany as MallLogisticsCompanyModel;

/**
* 快递公司表
*/
class MallLogisticsCompany extends Base
{
    use CURDController;
    protected $urlPre = '/mall/admin/mallLogisticsCompany/';

    private function getManageModel()
    {
        return MallLogisticsCompanyModel::class;
    }

    private function ajaxSearch()
    {
        $rs = $this->parseSearchWhere(
            $this->getManageModel(),
            ['name' => 'like']
        )->append(['enable_text']);
        return json_return($rs);
    }

    /**
     * @param \suframe\form\Form $form
     * @throws \FormBuilder\Exception\FormBuilderException
     * @throws \ReflectionException
     */
    private function getFormSetting($form)
    {
        $form->setRuleByClass(\app\mall\ui\form\MallLogisticsCompanyForm::class);
    }

    /**
     * @param UITable $table
     */
    private function getTableSetting($table)
    {
        $table->createByClass(\app\mall\ui\table\MallLogisticsCompanyTable::class);
        $table->setButtons('add', ['title' => '增加', 'url' => $this->urlABuild('update')]);
        $table->setEditOps($this->urlA('update'), ['id']);
        $table->setDeleteOps($this->urlA('delete'), ['id']);
    }

    public function getJson()
    {
        $list = MallLogisticsCompanyModel::order('inx', 'desc')
            ->order('id', 'asc')
            ->where('enable', YesNoEnum::YES)
            ->field(['id', 'name'])
            ->limit(0, 30)
//            ->cache('MallLogisticsCompany', 3600)
            ->select();
        return json_return($list->toArray());
    }
}